import { ApolloServer } from '@apollo/server';
// import { buildSubgraphSchema } from '@apollo/subgraph';
// import gql from "graphql-tag";
import { readFileSync } from 'fs';
import path from 'path';
import { customerResolvers, adminResolvers } from './resolvers';

const typeDefs = readFileSync(path.join(__dirname, 'schema.graphql'), { encoding: 'utf-8' });

export class ApolloServers{
    custApolloServer:ApolloServer<any>;
    adminApolloServer:ApolloServer<any>;
    constructor(){
        this.custApolloServer = new ApolloServer({
            typeDefs,
            resolvers:customerResolvers
        });
        this.adminApolloServer = new ApolloServer({
            typeDefs,
            resolvers:adminResolvers,
        });
    }
    static instance:ApolloServers;
    static async init(){
        this.instance = new ApolloServers();
        await this.instance.custApolloServer.start();
        await this.instance.adminApolloServer.start();
    }
    static getInstance(){
        if(this.instance){
            return this.instance;
        }else{
            this.init();
            return this.instance;
        }
    }
}